package com.sline.test;

import java.util.*;

public class poker {
    public static void main(String[] args) {
        String[] number = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        String[] color = {"红桃", "方块", "黑桃", "梅花"};

        HashMap<Integer, String> hm = new HashMap<>();
        ArrayList<Integer> arr = new ArrayList<>();
        int index = 0;

        for (int i = 0; i < number.length; i++) {
            for (int j = 0; j < color.length; j++) {

                String pokerStr = color[j] + number[i];
                hm.put(index, pokerStr);
                arr.add(index);
                index++;
            }
        }

        hm.put(index, "小王");
        arr.add(index);
        index++;
        hm.put(index, "大王");
        arr.add(index);

        System.out.println("创建的扑克");
        System.out.println(hm);
        System.out.println(arr);
        System.out.println("--------------------");

        //打乱index
        Collections.shuffle(arr);
        System.out.println("打乱后的序号");
        System.out.println(arr);

        // 发牌
        TreeSet<Integer> zhangsan = new TreeSet<>();
        TreeSet<Integer> lisi = new TreeSet<>();
        TreeSet<Integer> wangwu = new TreeSet<>();
        TreeSet<Integer> dipai = new TreeSet<>();

        for (int i = 0; i < arr.size(); i++) {

            Integer in = arr.get(i);
            if (i >= arr.size() - 3) {
                dipai.add(in);
            } else if (i % 3 == 0) {
                zhangsan.add(in);
            } else if (i % 3 == 1) {
                lisi.add(in);
            } else if (i % 3 == 2) {
                wangwu.add(in);
            } else {
                System.out.println("发牌出错了");
            }
        }

        System.out.println("-----------看牌啦----------");
        // 看牌
        lookPoker(hm, zhangsan, "张三");
        lookPoker(hm, lisi, "李四");
        lookPoker(hm, wangwu, "王五");
        lookPoker(hm, dipai, "底牌");
    }

    public static void lookPoker(HashMap<Integer, String> hm, TreeSet<Integer> ts, String name) {
        System.out.print(name + "的牌是: ");
        for (Integer i : ts) {
            System.out.print(hm.get(i) + ", ");
        }
        System.out.println();
    }
}
